package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.user.UserInfo;
import com.atguigu.tingshu.model.user.UserPaidTrack;
import com.atguigu.tingshu.user.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.User;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "用户管理接口")
@RestController
@RequestMapping("api/user/userInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class UserInfoApiController {

	@Autowired
	private UserInfoService userInfoService;


	@GetMapping("getUserInfoById/{userId}")
	public Result<UserInfo>  getUserInfoById(@PathVariable Long userId){
		UserInfo userInfo = this.userInfoService.getById(userId);

		return 	Result.ok(userInfo);
	}

	@GuiGuLogin
	@GetMapping("isPaidAlbum/{albumId}")
	public Result<Boolean> isPaidAlbum(@PathVariable Long albumId){
	Boolean b
		 = this.userInfoService.isPaidAlbum(albumId);
		return Result.ok(b);
	}

	@GuiGuLogin
	@GetMapping("getPaidTracks/{albumId}")
	public Result<List<UserPaidTrack>> getPaidTracks(@PathVariable Long albumId) {
		List<UserPaidTrack> list = this.userInfoService.getPaidTracks(albumId);
		return Result.ok(list);
	}

	@Operation(summary = "定时任务远程调用修改用户的VIP状态")
	@PostMapping ("/updateExpiredVipStatus")
	public Result updateExpiredVipStatus(){
		this.userInfoService.updateExpiredVipStatus();
		return Result.ok();
	}


}

